package com.java01.apache.commons.exec;

import java.io.IOException;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.ExecuteWatchdog;

public class WatchDogSnippet {

	public static void main(String[] args) {
		String line = "calc";
		CommandLine commandLine = CommandLine.parse(line);
		ExecuteWatchdog watchdog = new ExecuteWatchdog(6000);
		DefaultExecutor executor = new DefaultExecutor();
		executor.setWatchdog(watchdog);
		try {
			int exitValue = executor.execute(commandLine);
			System.out.println(exitValue);
		} catch (ExecuteException e) {
			System.err.println(e.getMessage());
		} catch (IOException e) {
			System.err.println(e.getMessage());
		}
	}
}
